package cn.wolfcode.shop.seckillserver.web.controller.frontend;

import cn.wolfcode.shop.member.domain.User;

import java.sql.*;

public class MyCatTest {

    public static void main(String[] args) {
        try {
            //inster();
            select();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void select() throws Exception {
        Connection conn = MyCatTest.getConn();
        String sql = "SELECT * FROM t_order WHERE orderNo = 2";

        PreparedStatement pstmt = conn.prepareStatement(sql);
        ResultSet resultSet = pstmt.executeQuery();
        while (resultSet.next()){
            int orderNo = resultSet.getInt("orderNo");
            String name = resultSet.getString("name");
            System.out.println(orderNo+" : "+name);
        }
        pstmt.close();
        conn.close();
    }

    private static void inster() throws Exception {
        Connection conn = MyCatTest.getConn();
        String sql = "insert into t_order(orderNo, name)values(?,?)";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setInt(1,2);
        pstmt.setString(2, "苹果手机");
        pstmt.addBatch();
        pstmt.executeBatch();
        pstmt.close();
        conn.close();
    }


    public static Connection getConn() throws Exception {
        String url = "jdbc:mysql://192.168.145.135:8066/TESTDB";
        String username = "root";
        String password = "123456";
        String driver = "com.mysql.jdbc.Driver";
        Class.forName(driver);
        return DriverManager.getConnection(url, username, password);
    }

    /*Communications link failure*/
}
